﻿@{
    ViewData["Title"] = "List";
}
@section Aside
    {
    @Html.Partial("AsidePartial")
}
<ol class="breadcrumb">
    <li><span class="glyphicon glyphicon-home"></span>  <a asp-page="/Manage/Index">首页</a></li>
    <li><a asp-controller="Content" asp-action="List">内容管理</a></li>
    <li class="active">内容列表</li>
</ol>
<div id="gdtoolbar">
    <a asp-controller="Content" asp-action="Add" class="btn btn-success"><span class="glyphicon glyphicon-plus"></span> 添加</a>
    <a id="btn-del" href="#" class="btn btn-danger"><span class="glyphicon glyphicon-remove"></span> 删除</a>
</div>

<table id="datagrid"></table>
@section css{
    <link href="~/lib/bootstrap-table/dist/bootstrap-table.min.css" rel="stylesheet" />
    <link href="~/lib/bootstrap3-dialog/dist/css/bootstrap-dialog.min.css" rel="stylesheet" />
}

@section scripts{

    @await Html.PartialAsync("_ValidationScriptsPartial")
    <script src="~/lib/bootstrap-table/dist/bootstrap-table.min.js"></script>
    <script src="~/lib/bootstrap3-dialog/dist/js/bootstrap-dialog.min.js"></script>
    <script type="text/javascript">
        function queryParams(params){
            var tempParams = {
                categoryId: '@ViewData["id"]',
                pageSize: params.limit,
                pageIndex: params.offset + 1,
                type: '@ViewData["type"]'
            }
            return tempParams;
        }
        $(document).ready(function () {
            $('#datagrid').bootstrapTable({
                queryParams: queryParams,
                url: '@Url.Content("~/Member/Content/ListJson")',
                pagination: true,
                pageSize: 10,
                sidePagination: 'server',
                toolbar: '#gdtoolbar',
                showRefresh: true,
                showColumns: true,
                columns: [{
                    checkbox: true
                }, {
                    field: 'contentId',
                    title: 'ID'
                }, {
                    field: 'title',
                    title: '标题',
                    formatter: function (value, row, index) {
                        return '[<a href="@Url.Content("~/Member/Content/List/")' + row.categoryId + '">' + row.categoryName + '</a>]<a href="@Url.Content("~/Member/Content/Modify/")' + row.contentId + '">' + value + '</a>';
                    }
                }, {
                    field: 'moduleType',
                    title: '类型',
                    formatter: function (value, row, index) {
                        switch (value) {
                            case 2:
                                return '文章';
                        }
                    }
                }, {
                    field: 'inputer',
                    title: '录入者'
                }, {
                    field: 'hits',
                    title: '点击数'
                }, {
                    field: 'createTime',
                    title: '创建时间'
                }, {
                    field: 'status',
                    title: '状态'
                }
                ]
            });

            //删除按钮
            $("#btn-del").click(function () {
                var checkRows = $('#datagrid').bootstrapTable('getSelections');
                if (checkRows.length == 0) BootstrapDialog.alert({
                    title: '消息',
                    message: '请选择要删除的内容',
                    type: BootstrapDialog.TYPE_WARNING,
                    buttonLabel: '确定'
                });
                else {
                    BootstrapDialog.confirm({
                        title: '确认',
                        message: '确认删除已选的【' + checkRows.length + '】篇内容',
                        type: BootstrapDialog.TYPE_DANGER,
                        closable: true,
                        draggable: true,
                        btnCancelLabel: '取消',
                        btnOKLabel: '删除',
                        btnOKClass: 'btn-danger',
                        callback: function (result) {
                            if (result) {
                                $.each(checkRows, function (index, value) {
                                    $.post('@Url.Content("~/Member/Content/DeleteJson")', { id: value.contentId }, function (resultdata) {
                                     });
                                });
                                BootstrapDialog.alert({
                                    title: '消息',
                                    message: '成功删除完成',
                                    type: BootstrapDialog.TYPE_WARNING,
                                    closable: true,
                                    draggable: true,
                                    buttonLabel: '确定',
                                    callback: function () {
                                        $('#datagrid').bootstrapTable('refresh');
                                    }
                                });
                            }
                        }
                    });
                }
            });
        });
    </script>


}